--script to unload stored procedures definition

declare cproc cursor for
select a.id,u.name,a.name, 
	(select count(*) from sysdepends d,sysobjects o where d.depid=o.id and o.type='P' and d.id=a.id) dep 
from sysobjects a,sysusers u
where a.type='P'  and a.uid=u.uid
order by 4,3,2

go

declare @id int
declare @user varchar(100)
declare @name varchar(100)
declare @dep int

declare @count int
declare @text varchar(255)

open cproc
 
fetch cproc into @id,@user,@name,@dep
 
while (@@sqlstatus = 0) begin 
	select "if exists(select name" + char(10) + 
			"	from dbo.sysobjects" + char(10) + 
			"	where name='" + @name + "'" + char(10) + 
			"	and type='P'" + char(10) + 
			"	and uid = user_id('"+@user+"'))"+ char(10) + 
			"   drop procedure "+@user+"." + @name + char(10) + 
			"go" + char(10)
	select text from syscomments where id=@id 
	/* order by colid2,colid !!!stupid thing but with order by it's not working for 11.9.2!!!*/
	
	select char(10) + "go" + char(10) + char(10)
	fetch cproc into @id,@user,@name,@dep
end 
 
close cproc
deallocate cursor cproc
go
